import sys
from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel, QVBoxLayout, QWidget
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QPainter, QPen, QColor


CENTER_X=600; CENTER_Y=400; SCALE=1;N=6
class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("FormationDrone")
        self.resize(1200,800)
        self.label = QLabel()
        self.label.setAlignment(Qt.AlignmentFlag.AlignLeft|Qt.AlignmentFlag.AlignTop)
        central = QWidget(); lay = QVBoxLayout(central); lay.addWidget(self.label)
        self.setCentralWidget(central)
        

    def draw(self):
        if not self.label.pixmap() or self.label.pixmap().size()!=self.label.size():
            self.label.setPixmap(self.label.grab())
        pm = self.label.pixmap()
        painter = QPainter(pm)
        painter.fillRect(pm.rect(), QColor(20,20,40))

        pen_grid = QPen(QColor(120,120,120), 1, Qt.PenStyle.DotLine)

        # 画网格
        painter.setPen(pen_grid)
        for d in range(-1000,1001,200):
            xx = CENTER_X + d*SCALE; yy = CENTER_Y - d*SCALE
            painter.drawLine(int(xx),0,int(xx),800)
            painter.drawLine(0,int(yy),1200,int(yy))

        painter.end()
        self.label.setPixmap(pm)

# ---------------- main ----------------
if __name__=='__main__':
    app=QApplication(sys.argv)
    w=MainWindow(); 
    w.draw()
    w.show()
    sys.exit(app.exec())